<template>
	<view>
		<image src="../../static/login/top3.png" mode="widthFix" class="top"></image>
		<image src="../../static/login/logo.jpg" mode="widthFix" class="logo"></image>
		<view class="desc">
			<text class="name">专业代驾 服务第一</text>
		</view>
		<button class="btn" @tap="wxLogin()">司机登陆</button>
		<view class="register-container">
			没有账号?
			<text class="link" @tap="toRegisterPage()">立即注册</text>
		</view>
		<text class="remark">小程序仅限于飞驰专车代驾使用,登录前请先进行微信注册,注册前请消息阅读注册需求和使用流程</text>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {};
		},
		methods: {
			toRegisterPage() {
				//跳转注册页面
				uni.navigateTo({
					url: "../register/register"
				})
			},
			wxLogin() {
				console.log("喻瑜");
				let _this = this;
				uni.showLoading({
					title: "登录中..."
				});

				wx.login({
					success(res) {
						//拿到微信授权码
						let openIdCode = res.code;
						_this.post("/uaa/app/login/wechat/login/" + openIdCode, (result) => {
							console.log(result);
							let {
								success,
								message,
								data
							} = result.data;
							if (success) {
								//成功
								uni.showToast({
									title: message,
									icon: "success",
									duration: 2000
								});
								//setTimeout定时器,当成功执行以后页面停留展示提示消息后两秒跳转页面
								setTimeout(() => {
									uni.setStorageSync("tokenName", data.tokenName);
									uni.setStorageSync("tokenValue", data.tokenValue);
									uni.setStorageSync("LoginInfoVo", data.login);
									//这是跳转到这个workbench页面
									uni.switchTab({
										url: "/pages/workbench/workbench"
									})
								}, 2000)
							} else {
								//失败
								uni.showToast({
									title: message,
									icon: "error",
									duration: 2000
								})
							}
							console.log("喻瑜");
						})
					}
				})
			},
			onLoad: function() {}
		}
	};
</script>

<style lang="less">
	@import url('login.less');
</style>